extends Talent
func init():
	name = "星之祈愿"

func get_info():
	return "立即提高100点血量与上限，每回合玩家血量回复20点并获得20金币和10经验,立刻获得一个投影仪\n开启祈愿(十连生物)和盲盒(五连装备)"

var xx = null
var step = 0
var layertxt
var gachaGrid = null
var base = globalData.infoDs["g_alxBase"]
var n=0
var tt = 0
var t1
var t2
var t3
var t4

func _connect():
	sys.main.connect("onBattleReady",self,"onBattleReady")
	sys.main.player.maxHp += 100
	sys.main.player.plusHp(100)
	sys.main.player.addItem(sys.newItem("i_Hidetyy"))
	battleUI()
	var niudanBtn1 = Button.new()
	niudanBtn1.text = "祈愿"
	niudanBtn1.margin_top = 50
	niudanBtn1.margin_left = 1270
	sys.main.get_node("ui").add_child(niudanBtn1)
	niudanBtn1.connect("pressed",self,"qiyuan")
	var niudanBtn2 = Button.new()
	niudanBtn2.text = "盲盒"
	niudanBtn2.margin_top = 100
	niudanBtn2.margin_left = 1270
	sys.main.get_node("ui").add_child(niudanBtn2)
	niudanBtn2.connect("pressed",self,"wakuang")
	while(sys.main==null):
		yield(sys.get_tree().create_timer(0.5),"timeout")
	if globalData.infoDs.has("g_ADDTALENT"):
		yield(sys.get_tree().create_timer(0.5),"timeout")
	else:
		t1=preload("res://ui/talentBtn/talentBtn.tscn").instance()
		t2=preload("res://ui/talentBtn/talentBtn.tscn").instance()
		sys.main.get_node("ui/player/GridContainer").add_child(t1)
		sys.main.get_node("ui/player/GridContainer").add_child(t2)
	t3=preload("res://ui/talentBtn/talentBtn.tscn").instance()
	t4=preload("res://ui/talentBtn/talentBtn.tscn").instance()
	sys.main.get_node("ui/player/GridContainer").add_child(t3)
	sys.main.get_node("ui/player/GridContainer").add_child(t4)
	if sys.main.player.is_connected("onPlusLv",self,"change")==false:
		sys.main.player.connect("onPlusLv",self,"change")
	change()

func change():
	if globalData.infoDs.has("g_ADDTALENT"):
		tt = 2
	else: 
		if sys.main.player.lv>=9 && n<1:
			n+=1
			t1.setStage(1)
		if sys.main.player.lv>=10 && n<2:
			n+=1
			t2.setStage(1)
	if sys.main.player.lv>=11 && n<3-tt:
		n+=1
		t3.setStage(1)
	if sys.main.player.lv>=12 && n<4-tt:
		n+=1
		t4.setStage(1)

func onBattleReady():
	sys.main.player.plusHp(20)
	sys.main.player.plusGold(20)
	sys.main.player.plusEmp(10)
	kunnan()

func kunnan():
	step = sys.main.guankaMsg.lvStep - 2
	if layertxt != null:
		layertxt.text="当前层数：%d" % (step)
	for i in range(0,10):
		for j in range(0,6):
			var cha=sys.main.matCha(Vector2(i,j))
			if cha != null:
				if cha.team == 2:
					if step > 135:
						cha.attAdd.maxHp += 60 * step
						cha.plusHp(60 * step)
						cha.attAdd.def += 4 * step
						cha.attAdd.mgiDef += 4 * step
						cha.attAdd.atk += 4 * step
						cha.attAdd.mgiAtk += 4 * step
						cha.attAdd.cri += 0.005 * step
						cha.attAdd.spd += 0.015 * step
						cha.attAdd.cd += 0.015 * step
						layertxt.text="当前层数:%d,当前敌军加成:血量%d 四维%d 双速%d%% 暴击%d%%"% [step, 60 * step, 4 * step, 1.5 * step, 0.5 * step]
					elif step > 108:
						cha.attAdd.maxHp += 50 * step
						cha.plusHp(50 * step)
						cha.attAdd.def += 4 * step
						cha.attAdd.mgiDef += 4 * step
						cha.attAdd.atk += 4 * step
						cha.attAdd.mgiAtk += 4 * step
						cha.attAdd.cri += 0.004 * step
						cha.attAdd.spd += 0.01 * step
						cha.attAdd.cd += 0.01 * step
						layertxt.text="当前层数:%d,当前敌军加成:血量%d 四维%d 双速%d%% 暴击%d%%"% [step, 50 * step, 4 * step, 1 * step, 0.4 * step]
					elif step > 81:
						cha.attAdd.maxHp += 40 * step
						cha.plusHp(40 * step)
						cha.attAdd.def += 3 * step
						cha.attAdd.mgiDef += 3 * step
						cha.attAdd.atk += 3 * step
						cha.attAdd.mgiAtk += 3 * step
						cha.attAdd.cri += 0.004 * step
						cha.attAdd.spd += 0.01 * step
						cha.attAdd.cd += 0.01 * step
						layertxt.text="当前层数:%d,当前敌军加成:血量%d 四维%d 双速%d%% 暴击%d%%"% [step, 40 * step, 3 * step, 1 * step, 0.4 * step]
					elif step > 54:
						cha.attAdd.maxHp += 30 * step
						cha.plusHp(30 * step)
						cha.attAdd.def += 2 * step
						cha.attAdd.mgiDef += 2 * step
						cha.attAdd.atk += 2 * step
						cha.attAdd.mgiAtk += 2 * step
						cha.attAdd.cri += 0.002 * step
						cha.attAdd.spd += 0.008 * step
						cha.attAdd.cd += 0.008 * step
						layertxt.text="当前层数:%d,当前敌军加成:血量%d 四维%d 双速%d%% 暴击%d%%"% [step, 30 * step, 2 * step, 0.8 * step, 0.2 * step]
					elif step > 20:
						cha.attAdd.maxHp += 20 * step
						cha.plusHp(20 * step)
						cha.attAdd.def += 2 * step
						cha.attAdd.mgiDef += 2 * step
						cha.attAdd.atk += 2 * step
						cha.attAdd.mgiAtk += 2 * step
						cha.attAdd.cri += 0.002 * step
						cha.attAdd.spd += 0.005 * step
						cha.attAdd.cd += 0.005 * step
						layertxt.text="当前层数:%d,当前敌军加成:血量%d 四维%d 双速%d%% 暴击%d%%"% [step, 20 * step, 2 * step, 0.5 * step, 0.2 * step]
				elif cha.team == 1:
					cha.plusHp(cha.att.maxHp)
					cha.attAdd.defR = min(0.6, cha.attAdd.defR)
					cha.upAtt()
	
func checkEmpty():
	for i in sys.main.btGrid.get_children():
		if i.get_children().size() == 0:
			i.queue_free()
		
	if layertxt != null:
		layertxt.text="当前层数：%d" % (sys.main.guankaMsg.lvStep - 2)
			
func battleUI():
	#战斗背景
	layertxt = Label.new()
	layertxt.text="当前层数：%d" % (sys.main.guankaMsg.lvStep - 2)
	layertxt.margin_left = 300
	layertxt.margin_right = 1180
	layertxt.align=1
	sys.main.get_node("ui").add_child(layertxt)
	layertxt.visible=true

func qiyuan():
	if  sys.main.player.gold >= 1250:
		roPollItem1(0,10)
		sys.main.player.plusGold(-1250)
	else:
		sys.newBaseMsg("钱不够呢~","祈愿要1250金哦，亲~")
func wakuang():
	if  sys.main.player.gold >= 1200:
		roPollItem1(5,0)
		sys.main.player.plusGold(-1200)
	else:
		sys.newBaseMsg("钱不够呢~","盲盒需要1200金呢，亲~")

func roPollItem1(itm,cha):
	xx = sys.newMsg("jiangLiMsg")
	xx.get_node("Panel/Label").text = "恭喜！祈愿出以下亚比！"
	xx.get_node("Panel/Button").connect("pressed",self,"MsgOk")
	gachaGrid = GridContainer.new()
	gachaGrid.set_columns(5)
	xx.get_node("Panel/CenterContainer").add_child(gachaGrid)
	if itm >=1:
		for i in range(itm):
			var item1 = sys.newItem(itemData.rndPool.rndItem().id)
			sys.main.player.addItem(item1)
			#var xx1 = sys.newBaseMsg("盲盒里面居然有以下装备！","")
			xx.get_node("Panel/Label").text = "盲盒里面居然有以下装备！"
			var itemBt = load("res://ui/item/item.tscn").instance()
			itemBt.init(item1)
			itemBt.margin_left = 100
			itemBt.margin_top= 100
			gachaGrid.add_child(itemBt)
			# var itemRect = TextureRect.new()
			# itemRect.set_texture(base.loadImg(itemData.infoDs[item1.id].dir,"%s/ico.png" % item1.id))
			# xx.add_child(itemRect)
	if cha >=1:
		for i in range(cha):
			var rngnum = sys.rndRan(1,100)#概率
			var rng = 0
			if rngnum <= 5:
				rng = 4
			elif rngnum <= 15:
				rng = 3
			elif rngnum <= 30:
				rng = 2
			else:
				rng = 1
			var chas1 = []
			for i in chaData.rndPool.items:
				if i[0].lv ==rng:
					chas1.append(i[0])
			chas1.shuffle()
			var cha1 = sys.main.newChara(chas1[0].id)
			sys.main.player.addCha(cha1)
			var chaBt = preload("res://ui/itemBt/itemBt.tscn").instance()
			chaBt.id = cha1.id
			#sys.main.player.addCha(sys.main.newChara(cha1.id))
			gachaGrid.add_child(chaBt)
	xx.show()

func MsgOk():
	pass

func rngcha1(obj1):
	if obj1.lv == 1:return true
func rngcha2(obj1):
	if obj1.lv == 2:return true
func rngcha3(obj1):
	if obj1.lv == 3:return true
func rngcha4(obj1):
	if obj1.lv == 4:return true